<template>
  <div class="body">
    <div class="container">
      <div class="title"><span>商家登录</span></div>
      <div class="account">
        <input type="text" placeholder="这里输入账号..." v-model="account" />
      </div>
      <div class="password">
        <input type="text" placeholder="这里输入密码..." v-model="password" />
      </div>
      <div class="buttons">
        <el-button
          type="primary"
          plain
          class="button"
          @click="routeTo('/signUp')"
          >去注册</el-button
        >
        <el-button type="success" plain class="button" @click="doLogin"
          >登录</el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import { userAxios } from "../common/network/request";
export default {
  data() {
    return {
      account: "",
      password: "",
    };
  },
  methods: {
    routeTo(path) {
      this.$router.push(path);
    },
    doLogin() {
      if (this.account == "" || this.password == "") {
        this.$message({
          type: "error",
          message: "不可为空",
        });
      } else {
        userAxios({
          url: "/business/doLogin",
          method: "get",
          params: {
            account: this.account,
            password: this.password,
          },
        }).then((res) => {
          if (res == "" || res == null) {
            this.$message({
              type: "error",
              message: "账号或密码错误",
            });
          } else {
            this.$store.commit("setToken", res);
            this.$message({
              type: "success",
              message: "登陆成功",
            });
            this.$router.push('/index')
          }
        });
      }
    },
  },
};
</script>

<style scoped>
.body {
  height: 100%;
  background-color: rgb(132, 204, 252);
  display: flex;
  align-items: center;
}

.container {
  height: 300px;
  width: 400px;
  background-color: white;
  border-radius: 19px;
  margin: auto;
  border: 1px solid rgb(224, 220, 220);
  display: flex;
  flex-direction: column;
  padding: 30px;
}

.title {
  flex: 1;
  font-size: 24px;
  color: #606266;
  display: flex;
  align-items: center;
  letter-spacing: 3px;
}

.title span {
  text-align: center;
  margin: auto;
}

.account {
  flex: 1;
  display: flex;
  align-items: center;
}

input {
  outline: none;
  border: none;
  height: 80%;
  width: 80%;
  font-size: 15px;
  font-weight: 300;
  border-bottom: 1px solid gray;
  margin: auto;
  text-align: center;
}

.password {
  flex: 1;
  display: flex;
  align-items: center;
}

.buttons {
  flex: 2;
  display: flex;
  align-items: center;
  justify-items: center;
  padding-left: 40px;
  padding-right: 40px;
}

.button {
  flex: 1;
}
</style>